let v = new Vue({
    el:'#main-container',
    data:function () {
        return {
            settings:{
                data:{
                    simpleData: {
                        enable:true,
                        pIdKey:'parentId'
                    }
                },
                callback:{
                    onClick:this.onClick,
                    // beforeEditName:this.beforeEditName
                },
                view:{
                    // fontCss:this.fontCss
                    // addHoverDom:this.addHoverDom,
                    // removeHoverDom:this.removeHoverDom
                },
                // edit:{
                //     enable: true
                // },
            },
            nodes:[],
            pageInfo:{
                pageSize:5,
            },
            params:{

            },
            officeName:'全部',
        }
    },
    methods:{
        selectByPage:function (page,pageSize) {
            axios({
                url:`manager/role/selectRoleAndOffice/${page}/${pageSize}`,
                method:'post',
                data: this.params
            }).then(resp => {
                this.pageInfo = resp.data.obj;
            }).catch(error => {
                layer.msg(error.message);
            })
        },
        select:function(page,pageSize){
            this.params = {};
            this.selectByPage(page,pageSize);
        },
        initTree:function () {
            axios({
                url:'manager/office/list',
                method: 'get'
            }).then(resp => {
                this.nodes = resp.data.obj;
                this.nodes[this.nodes.length] = {id:0,name:'机构列表',open:true};
                let treeObj = $.fn.zTree.init($("#pullDownTreeone"),this.settings,this.nodes)
            }).catch(error => {
                console.log(error);
            });
        },
        onClick: function (event, treeId, treeNode) {
            // parent.layer.parentName = treeNode.name;
            // parent.layer.parentId = treeNode.id;
            // parent.layer.parentIds = treeNode.parentIds;
            this.officeName = treeNode.name;
            this.params.officeName = treeNode.name;
            // parent.layer.tNode = treeNode;
            // let index = parent.layer.getFrameIndex(window.name);
            // parent.layer.close(index);
        },
        toFenpei:function (id) {
            layer.rid = id;
            layer.open({
                type: 2,
                title: '分配人员',
                area: ['80%', '80%'],
                content: 'manager/role/toFenpei',
                end:() => {

                }
            })
        },
        toUpdate:function (role) {
            layer.obj = role;
            layer.open({
                type: 2,
                title: '编辑',
                area: ['80%', '80%'],
                content: 'manager/role/toUpdate',
                end:() => {
                    this.selectByPage(this.pageInfo.pageNum,this.pageInfo.pageSize);
                }
            })
        }
    },
    created:function () {
        this.select(1,this.pageInfo.pageSize);
    },
    mounted:function () {
        this.initTree();
    }
})